package cn.amaake.magicplugin.nacos.util.parse;

import cn.amaake.magicplugin.nacos.util.AbstractConfigParse;
import com.alibaba.nacos.api.config.ConfigType;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class DefaultJsonConfigParse extends AbstractConfigParse {
    public DefaultJsonConfigParse() {
    }

    public Map<String, Object> parse(String configText) {
        final AtomicReference<Map<String, Object>> result = new AtomicReference();
        configText = configText.replaceAll("\t", "");
        DefaultYamlConfigParse.process(new DefaultYamlConfigParse.MatchCallback() {
            public void process(Map<String, Object> map) {
                result.set(map);
            }
        }, DefaultYamlConfigParse.createYaml(), configText);
        return (Map)result.get();
    }

    public String processType() {
        return ConfigType.JSON.getType();
    }
}
